package pro.spring.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pro.spring.inter.ImagesMapper;
import pro.spring.inter.AdminMapper;
import pro.spring.model.Admin;
import pro.spring.vo.PaginationVo;

@Service
public class AdminService{

	@Autowired
	private AdminMapper AdminMapper;
	
	@Autowired
	private ImagesMapper ImagesMapper;
	
	public int deleteByPrimaryKey(Integer id) {
		return AdminMapper.deleteByPrimaryKey(id);
	}

	public int insert(Admin record) {
		return AdminMapper.insert(record);
	}

	public Admin selectByPrimaryKey(Integer id) {
		Admin a = AdminMapper.selectByPrimaryKey(id);
		a.setImage(ImagesMapper.selectByPrimaryKey(a.getImgaesImId()));
		return a;
	}

	public int updateByPrimaryKey(Admin record) {
		return AdminMapper.updateByPrimaryKey(record);
	}
	
	public int selectByNew() {
		return AdminMapper.selectByNew();
	}
	
	public Admin selectLogin(String name ,String pass) {
		return AdminMapper.selectLogin(name, pass);
	}
	
	
	public PaginationVo<Admin> getPaginationInfo(int pagenum,int pagesize){
		//int pagenum是当前的页码,int pagesize是每页显示的数据数量
		PaginationVo<Admin> pageVo=new PaginationVo<Admin>();
		//一定要在setPageCount()方法之后执行setPageNum
		pageVo.setCount(AdminMapper.selectCount());
		pageVo.setRows(pagesize);
		pageVo.setPageNum(pagenum);
		List<Admin> a = AdminMapper.selectListPage(pageVo.getOffset(), pageVo.getRows());
		for(Admin admin:a){
			admin.setImage(ImagesMapper.selectByPrimaryKey(admin.getImgaesImId()));
		}
		pageVo.setList(a);
		return pageVo;
	}
	
	public Admin selectByNameForVedio(String aName){
		return AdminMapper.selectByNameForVedio(aName);
	}
}
